﻿<Window x:Class="BlobExplorer.ExplorerWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:cmd="clr-namespace:BlobExplorer"
    Title="Azure Blob Storage Explorer" Height="600" Width="900" Icon="IconCloudStorage.jpg" >
    <Window.InputBindings>
        <KeyBinding Key="C" Modifiers="Ctrl" Command="cmd:Commands.CopyUri" />
        <KeyBinding Key="Ins" Modifiers="Ctrl" Command="cmd:Commands.CopyUri" />
        <KeyBinding Key="Del" Command="cmd:Commands.DeleteBlob" />
    </Window.InputBindings>
    <Grid>
        <Grid.Resources>
            <BooleanToVisibilityConverter x:Key="visConverter"/>
            <cmd:AccessControlToImageConverter x:Key="imgConverter" />
            <cmd:NotConverter x:Key="notConverter"/>
            <cmd:NullToBooleanConverter x:Key="n2bConverter"/>
        </Grid.Resources>
        
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="3"/>
            <ColumnDefinition Width="4*"/>
        </Grid.ColumnDefinitions>
        <Menu Grid.Row="0" Grid.ColumnSpan="3">
            <Menu.Background>
                <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
                    <LinearGradientBrush.GradientStops>
                        <GradientStop Offset="0" Color="LightBlue"/>
                        <GradientStop Offset="1" Color="AliceBlue"/>
                    </LinearGradientBrush.GradientStops>
                </LinearGradientBrush>
            </Menu.Background>
            <MenuItem Header="_File">
                <MenuItem Header="_Connect">
                    <MenuItem Header="Development Storage" Command="cmd:Commands.Connect" CommandParameter="true" IsEnabled="{Binding Connected, Converter={StaticResource notConverter}}"/>
                    <MenuItem Header="Cloud Storage" Command="cmd:Commands.Connect" CommandParameter="false" IsEnabled="{Binding Connected, Converter={StaticResource notConverter}}"/>
                </MenuItem>
                <MenuItem Header="_Disconnect" Command="cmd:Commands.Disconnect" IsEnabled="{Binding Connected}"/>
                <Separator/>
                <MenuItem Header="E_xit" Command="cmd:Commands.Exit"/>
            </MenuItem>
            <MenuItem Header="_Action">
                <MenuItem Header="Add _Container" Command="cmd:Commands.AddContainer" IsEnabled="{Binding Connected}"/>
                <MenuItem Header="Delete C_ontainer" Command="cmd:Commands.DeleteContainer" IsEnabled="{Binding ElementName=contents, Path=SelectedItem, Converter={StaticResource n2bConverter}}"/>
                <Separator/>
                <MenuItem Header="_Get Blob" Command="cmd:Commands.GetBlob" IsEnabled="{Binding ElementName=details, Path=SelectedItem, Converter={StaticResource n2bConverter}}"/>
                <MenuItem Header="O_pen Blob" Command="cmd:Commands.OpenBlob" IsEnabled="{Binding ElementName=details, Path=SelectedItem, Converter={StaticResource n2bConverter}}"/>
                <MenuItem Header="Add _Blob" Command="cmd:Commands.AddBlob" IsEnabled="{Binding ElementName=contents, Path=SelectedItem, Converter={StaticResource n2bConverter}}"/>
                <MenuItem Header="Delete B_lob" Command="cmd:Commands.DeleteBlob" IsEnabled="{Binding ElementName=details, Path=SelectedItem, Converter={StaticResource n2bConverter}}" InputGestureText="Del"/>
                <Separator/>
                <MenuItem Header="_View Metadata" Command="cmd:Commands.ViewMetadata" IsEnabled="{Binding ElementName=details, Path=SelectedItem, Converter={StaticResource n2bConverter}}"/>
                <MenuItem Header="Copy _Uri" Command="cmd:Commands.CopyUri" IsEnabled="{Binding ElementName=details, Path=SelectedItem, Converter={StaticResource n2bConverter}}" InputGestureText="Ctrl-C"/>
            </MenuItem>
            <MenuItem Header="_View">
                <MenuItem Header="_Refresh" Command="cmd:Commands.Refresh"/>
            </MenuItem>
            <MenuItem Header="_Help">
                <MenuItem Header="_About" Command="cmd:Commands.About"/>
            </MenuItem>

        </Menu>
        <Grid Grid.Row="1">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
            <TextBlock Padding="3">Containers</TextBlock>
            <ListBox x:Name="contents" Grid.Row="1" ItemsSource="{Binding Model.Containers}" Padding="5">
                <ListBox.Background>
                    <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
                        <LinearGradientBrush.GradientStops>
                            <GradientStop Offset="0" Color="White"/>
                            <GradientStop Offset="1" Color="AliceBlue"/>
                        </LinearGradientBrush.GradientStops>
                    </LinearGradientBrush>
                </ListBox.Background>
                <ListBox.ContextMenu>
                    <ContextMenu>
                        <MenuItem Header="Add _Container" Command="cmd:Commands.AddContainer" IsEnabled="{Binding Connected}"/>
                        <MenuItem Header="Delete C_ontainer" Command="cmd:Commands.DeleteContainer" IsEnabled="{Binding ElementName=contents, Path=SelectedItem, Converter={StaticResource n2bConverter}}"/>
                    </ContextMenu>
                </ListBox.ContextMenu>
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal">
                            <Image Source="{Binding Path=., Converter={StaticResource imgConverter}}" Height="16" Width="16"/>
                            <TextBlock Text="{Binding ContainerName}"/>
                        </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
            
        </Grid>
        <GridSplitter Grid.Row="1" Grid.Column="1" ResizeBehavior="PreviousAndNext" ResizeDirection="Columns" HorizontalAlignment="Stretch"/>
        
        <ListView x:Name="details" Grid.Row="1" Grid.Column="2" ItemsSource="{Binding Model.Blobs}" AllowDrop="{Binding Connected}" Drop="details_Drop">
            <ListView.Background>
                <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
                    <LinearGradientBrush.GradientStops>
                        <GradientStop Offset="0" Color="White"/>
                        <GradientStop Offset="1" Color="AliceBlue"/>
                    </LinearGradientBrush.GradientStops>
                </LinearGradientBrush>
            </ListView.Background>
            <ListView.ContextMenu>
                <ContextMenu>
                    <MenuItem Header="_Get Blob" Command="cmd:Commands.GetBlob" IsEnabled="{Binding ElementName=details, Path=SelectedItem, Converter={StaticResource n2bConverter}}"/>
                    <MenuItem Header="O_pen Blob" Command="cmd:Commands.OpenBlob" IsEnabled="{Binding ElementName=details, Path=SelectedItem, Converter={StaticResource n2bConverter}}"/>
                    <MenuItem Header="Add _Blob" Command="cmd:Commands.AddBlob" IsEnabled="{Binding ElementName=contents, Path=SelectedItem, Converter={StaticResource n2bConverter}}"/>
                    <MenuItem Header="Delete B_lob" Command="cmd:Commands.DeleteBlob" IsEnabled="{Binding ElementName=details, Path=SelectedItem, Converter={StaticResource n2bConverter}}" InputGestureText="Del"/>
                    <Separator/>
                    <MenuItem Header="_View Metadata" Command="cmd:Commands.ViewMetadata" IsEnabled="{Binding ElementName=details, Path=SelectedItem, Converter={StaticResource n2bConverter}}"/>
                    <MenuItem Header="Copy _Uri" Command="cmd:Commands.CopyUri" IsEnabled="{Binding ElementName=details, Path=SelectedItem, Converter={StaticResource n2bConverter}}" InputGestureText="Ctrl-C"/>
                </ContextMenu>
            </ListView.ContextMenu>
            <ListView.View>
                <GridView>
                    <GridViewColumn Header="Name" DisplayMemberBinding="{Binding Name}" Width="80"/>
                    <GridViewColumn Header="Content" DisplayMemberBinding="{Binding ContentType}" Width="150"/>
                    <GridViewColumn Header="Length" DisplayMemberBinding="{Binding ContentLength}" Width="60"/>
                    <GridViewColumn Header="Uri" DisplayMemberBinding="{Binding Uri}" Width="500"/>
                </GridView>
            </ListView.View> 
        </ListView>
        
        <TextBlock x:Name="status" TextWrapping="Wrap" Grid.Row="2" Grid.ColumnSpan="3">
            <TextBlock.Background>
                <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
                    <LinearGradientBrush.GradientStops>
                        <GradientStop Offset="0" Color="White"/>
                        <GradientStop Offset="1" Color="AliceBlue"/>
                    </LinearGradientBrush.GradientStops>
                </LinearGradientBrush>
            </TextBlock.Background>
        </TextBlock>
    </Grid>
</Window>
